package org.citywithincity.jobqueue;

import java.util.HashSet;
import java.util.Set;


class QueueManager implements QueueListener{
	private static final QueueManager instance = new QueueManager();
	private Set<Object> jobSet;
	
	private QueueManager(){
		jobSet = new HashSet<Object>();
	}
	@Override
	public synchronized void onAddJob(Object job) {
		jobSet.add(job);
	}

	@Override
	public synchronized void onRemoveJob(Object job) {
		jobSet.remove(job);
	}
	
	public synchronized boolean contains(Object job){
		return jobSet.contains(job);
	}
	/**
	 * 是否符合
	 * @param job
	 * @return
	 */
	public synchronized boolean contains(JobFilter filter){
		for (Object job : jobSet) {
			if(filter.accept(job)){
				return true;
			}
		}
		return false;
	}
	
	public static QueueManager getInstance() {
		return instance;
	}
	

	
}
